package com.example.microinvestcommon.util;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.List;

public class ChangeListAndJsonUtil {
    public static String ChangeToJson(List<List<Double>> data) throws Exception {
        ObjectMapper objectMapper = new ObjectMapper();
        return objectMapper.writeValueAsString(data);
    }

    public static List<List<Double>> changeToList(String stockJson) throws Exception {
        ObjectMapper objectMapper = new ObjectMapper();
        return objectMapper.readValue(stockJson, new TypeReference<List<List<Double>>>() {});
    }

    // 解析一维数组
    public static List<Double> changeToListOneDim(String json) throws Exception {
        ObjectMapper objectMapper = new ObjectMapper();
        return objectMapper.readValue(json, new TypeReference<List<Double>>() {});
    }
}
